<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="工单号" prop="workOrderNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workOrderNumber" placeholder="请填写工单号" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设备编码" prop="equipmentCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.equipmentCode" placeholder="请填写设备编码" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="厂" prop="factory"
                :rules="[
                 ]" >
              <el-input v-model="inputForm.factory" placeholder="请填写厂" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="区域" prop="area"
                :rules="[
                 ]" >
              <el-input v-model="inputForm.area" placeholder="请填写区域" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="主体设备" prop="mainEquipment"
                :rules="[
                 ]" >
              <el-input v-model="inputForm.mainEquipment" placeholder="请填写主体设备" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务来源" prop="taskSource"
                :rules="[
                 ]" >
              <!-- <el-input v-model="inputForm.taskSource" placeholder="请填写任务来源"     ></el-input> -->
              <el-select v-model="inputForm.taskSource" placeholder="请填写任务来源" style="width:100%;" disabled="">
                <el-option v-for="taskSource in $dictUtils.getDictList('repair_source')" :label="taskSource.label" :value="taskSource.value" :key="taskSource.value" ></el-option>
              </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工内容" prop="roadworkContent"
                :rules="[
                 ]">
              <el-input v-model="inputForm.roadworkContent" placeholder="请填写施工内容" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="接办人" prop="unsuccessfulPeople"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.unsuccessfulPeople" placeholder="请填写接办人" disabled=""></el-input> -->
              <user-select :limit='1' :value="inputForm.unsuccessfulPeople" @getValue='(value) => {inputForm.unsuccessfulPeople=value}' @getUserName='getUserName(arguments)' disabled=""></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工号" prop="workNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workNumber" placeholder="请填写工号" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
                    <el-form-item label="检修标准工时" prop="overhaulPeople"
                        :rules="[
                         ]">
                      <el-input v-model="inputForm.overhaulPeople" placeholder="请填写检修标准工时" disabled=""></el-input>
                   </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="检修标准项目承办人数" prop="repirpeople"
                        :rules="[
                         ]">
                      <el-input v-model="inputForm.repirpeople" placeholder="请填写检修标准项目承办人数" disabled=""></el-input>
                   </el-form-item>
                </el-col>
        <el-col :span="12">
            <el-form-item label="完成时间" prop="completeTime"
                :rules="[
                 ]" >
              <!-- <el-input v-model="inputForm.completeTime" placeholder="请填写完成时间" ></el-input> -->
              <el-date-picker
                    style="width:100%;"
                    v-model="inputForm.completeTime"
                    type="datetime"
                    placeholder="选择日期时间"
                    default-time="12:00:00" disabled="">
              </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工时" prop="workTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workTime" placeholder="请填写工时"     disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="状态" prop="state"
                :rules="[
                 ]">
              <el-select v-model="inputForm.state" placeholder="请填状态" style="width:100%;" disabled="">
              <el-option v-for="state in $dictUtils.getDictList('repair_statement')" :label="state.label" :value="state.value" :key="state.value"></el-option>
              </el-select>
           </el-form-item>
        </el-col>
       <!-- <el-col :span="12">
            <el-form-item label="项目协办人" prop="projectMan"
                :rules="[
                 ]">
              <el-input v-model="inputForm.projectMan" placeholder="请填写项目协办人"     disabled=""></el-input>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="项目协办人" prop="projectMan"
                :rules="[
                 ]">
              <user-select :limit='10' :value="inputForm.projectMan" @getValue='(value) => {inputForm.projectMan=value}' @getUserName='getUserName(arguments)' disabled></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="检修项目开始时间" prop="startTime"
                :rules="[
                 ]" >
              <!-- <el-input v-model="inputForm.completeTime" placeholder="请填写完成时间" ></el-input> -->
              <el-date-picker
                    style="width:100%;"
                    v-model="inputForm.startTime"
                    type="datetime"
                    placeholder="选择日期时间"
                    default-time="12:00:00" disabled="">
              </el-date-picker>
              </el-form-item>
              </el-col>
        <el-col :span="12">
            <el-form-item label="实际完成时间" prop="actualCompleteTime"
                :rules="[
                 ]" >
              <el-input v-model="inputForm.actualCompleteTime" placeholder="请填写实际完成时间" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="完成情况" prop="completeSituation"
                :rules="[
                 ]">
              <el-input v-model="inputForm.completeSituation" placeholder="请填写完成情况"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="有无异常" prop="isAbnormal"
                :rules="[
                 ]">
              <el-input v-model="inputForm.isAbnormal" placeholder="请填写有无异常"     ></el-input>
           </el-form-item>
        </el-col>
         <!-- <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                  {required: true, message:'备注信息不能为空', trigger:'blur'}
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col> -->
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button :disabled="method === 'changestate'" @click="visible = false" v-if="method != 'editTime' && method != 'editTimes'">关闭</el-button>
      <el-button :disabled="method === 'changestate'" type="primary" v-if="method != 'view' && method != 'editTime' && method != 'editTimes'" @click="doSubmit()" v-noMoreClick>确认</el-button>
    </span>
    </el-dialog>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          workOrderNumber: '',
          equipmentCode: '',
          factory: '',
          area: '',
          mainEquipment: '',
          taskSource: '',
          roadworkContent: '',
          unsuccessfulPeople: '',
          workNumber: '',
          completeTime: '',
          actualCompleteTime: '',
          completeSituation: '',
          isAbnormal: '',
          startTime: '',
          workTime: '',
          state: '',
          projectMan: '',
          remarks: '',
          testId: '',
          overhaulPeople: '',
          repirpeople: '',
          processId: ''
        }
      }
    },
    components: {
      UserSelect
    },
    methods: {
       initDosubmit (name, id, times) {
        this.$http({
           url: `/sys/log/logId`,
           method: 'get'
         }).then(({data}) => {
           console.log(data.logId.roleNames)
           // if (data.logId.roleNames !== '项目负责人') {
           //   this.$alert('您没有此权限', '提示', {
           //     confirmButtonText: '确定',
           //     type: 'warning'
           //   })
           //    } else {
                console.log(data.logId.roleNames)
              this.init(name, id, times, data.logId.roleNames)
            // }
        })
        },
      init (method, id, times, rolenames) {
        this.method = method
        this.inputForm.id = id
        this.$http({
           url: `/sys/log/logId`,
           method: 'get'
         }).then(({data}) => {
           // if (data.logId.roleNames !== '检修作业长' && method !== 'view' && rolenames !== '项目负责人') {
           //   this.$alert('您没有此权限', '提示', {
           //     confirmButtonText: '确定',
           //     type: 'warning'
           //   })
           // } else {
        if (method === 'add') {
          this.title = `新建项目执行`
        } else if (method === 'edit' || method === 'editTime' || method === 'editTimes') {
          this.title = '修改项目执行'
        } else if (method === 'view') {
          this.title = '查看项目执行'
        }
        console.log(method)
        this.visible = true
        this.loading = true
        this.$nextTick(() => {
          console.log(method)
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view' || method === 'editTime' || method === 'editTimes' || method === 'changestate') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/flowform/form/projectPerform/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.projectPerform)
              if (method === 'changestate') {
                this.inputForm.state = 1
                this.doSubmit()
              }
              if (method === 'editTime') {
                this.inputForm.actualCompleteTime = times
                this.doSubmit()
              } else if (method === 'editTimes') {
                this.inputForm.startTime = times
                this.doSubmit()
              }
              this.loading = false
            })
          }
        })
           // }
           })
      },
      // 表单提交
      doSubmit () {
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'start_time',
            value: this.inputForm.startTime
          }
        })
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'actual_complete_time',
            value: this.inputForm.actualCompleteTime
          }
        })
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'complete_situation',
            value: this.inputForm.completeSituation
          }
        })
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'is_abnormal',
            value: this.inputForm.isAbnormal
          }
        })
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/flowform/form/projectPerform/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>
